<div class="alert-title">添加后台子账号</div>

<table class="user-info">
    <tr>
        <td class="title">用户名</td>
        <td class="field">
            <input type="text" class="am-form-field ui_account" value="" placeholder="">
        </td>
        <td class="copy"></td>
    </tr>
        
    <tr>
        <td class="title">用户组</td>
        <td class="field">
            <select data-am-selected class="ui_grade">
            </select>
        </td>
        <td class="copy"></td>
    </tr>
    
    <tr>
        <td class="title">姓名</td>
        <td class="field">
            <input type="text" class="admin_input ui_name" value="" placeholder="请输入姓名">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">密码</td>
        <td class="field">
            <input type="password" class="admin_input ui_password" value="" placeholder="请输入登录密码">
        </td>
        <td class="copy"></td>
    </tr>
</table>

<div class="button_line">
    <button class="btn-save common_button admin_button">保存</button>
    <button class="close common_button admin_button">关闭</button>
</div>

<script>
    // 取得用户组
    idNames = [];
    Classify.queryExt("roles", "idname", true, {}, function(r) {
        for (var i = 50; i <= 98; i++) {
            if (!r[i + ""]) continue;
            idNames.push({
                id: i,
                name: r[i + ""],
            });
        }

        // 填充用户组信息
        $(".ui_grade").empty();
        for (var i in idNames) {
            $(".ui_grade").append('<option value="' + idNames[i].id + '">' + idNames[i].name + '</option>');
        }
    });

    $(".close").click(function() {
        $("#add_account").remove();
    });
    $(".btn-save").click(function() {
        var uid = $(".ui_account").val().trim();
        var p = $(".ui_password").val().trim();
        var name = $(".ui_name").val().trim();
        if (uid == '') {
            alert2("请输入账号！", true);
            return;
        }
        if (p == '') {
            alert2("请输入登录密码！", true);
            return;
        }
        if (name == '') {
            alert2("请输入姓名！", true);
            return;
        }
        startLoading();
        CMD.add_account(uid, p, name, $(".ui_grade").val(), function() {
            stopLoading();
            $("#add_account").remove();
            if (window._f) _f();
        })
    });
    $("select").selected();
</script>